//
//  LookMoreWindowViewController.m
//  Beauty
//
//  Created by Snow on 16/9/13.
//  Copyright © 2016年 Snow. All rights reserved.
//

#import "LookMoreWindowViewController.h"
#import "GXMacro.h"
#import "GXNetWorkingParser.h"
#import "HotWindowCollectionViewCell.h"
#import "ModelOfLookMoreWindow.h"
#import "HotWindowViewController.h"
@interface LookMoreWindowViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) NSMutableArray *arrayOfDetailWindow;
@property (nonatomic, strong) UICollectionViewFlowLayout *layout;
@end

@implementation LookMoreWindowViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self handleData];
    [self createView];
}
- (void)handleData
{
    _arrayOfDetailWindow = [NSMutableArray array];
    [GXNetWorkingParser GETWithURL:@"http://www.wantease.com/mobile1/index.php?act=index&op=more_micro_personal_class_list" par:nil success:^(id responseObject) {
        NSDictionary *dic = responseObject[@"datas"];
        NSArray *arr = [dic objectForKey:@"micro_personal_class_list"];
        for (NSDictionary *dict in arr) {
            ModelOfLookMoreWindow *model = [[ModelOfLookMoreWindow alloc] init];
            [model setValuesForKeysWithDictionary:dict];
            [_arrayOfDetailWindow addObject:model];
        }
        [_collectionView reloadData];
} filed:^(NSError *error) {
    
}];
}
- (void)createView
{
    _layout = [[UICollectionViewFlowLayout alloc] init];
    _layout.itemSize = CGSizeMake((SCREEN_WIDTH - 30) / 2, 200);
    _layout.minimumLineSpacing = 10;
    _layout.minimumInteritemSpacing = 10;
    _layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64) collectionViewLayout:_layout];
    _collectionView.backgroundColor = [UIColor whiteColor];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    [_collectionView registerClass:[HotWindowCollectionViewCell class] forCellWithReuseIdentifier:@"HotWindowCollectionViewCell1"];
    [self.view addSubview:_collectionView];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _arrayOfDetailWindow.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    HotWindowCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HotWindowCollectionViewCell1" forIndexPath:indexPath];
    ModelOfLookMoreWindow *model = [_arrayOfDetailWindow objectAtIndex:indexPath.row];
    cell.labelOfTitle.text = model.favorites_class_name;
    cell.numberOfCut.text = [NSString stringWithFormat:@"共%@个瞬间", model.micro_personal_count];
    cell.numberOfCut.font = [UIFont systemFontOfSize:12];
    cell.arrayOfPic = model.micro_personal;
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    ModelOfLookMoreWindow *model = [_arrayOfDetailWindow objectAtIndex:indexPath.row];
    HotWindowViewController *vc = [[HotWindowViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
    vc.favorita_class_id = model.favorites_class_id;
    UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = barItem;
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
